
import Vue from 'vue'
import App from './App.vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import 'bootstrap/dist/css/bootstrap.min.css'
import 'bootstrap/dist/js/bootstrap.min.js'
import axios from 'axios'

import VueRouter from 'vue-router';
import login from './components/login.vue'
import subject from './components/subject.vue'


Vue.use(VueRouter); //挂载属性
//创建路由对象并配置路由规则
let router = new VueRouter({
  routes: [
      //配置路由
      { path: '/',name:'login', component: login },
      { path: '/subject',name:'subject',component: subject},
  ]
});
//路由守卫
router.beforeEach((to, from, next) => {
  // 如果访问的是登录页面
  if (to.path === '/') return next()
  // 如果访问的不是登录页面，则要先检查是否有token
  const tokenStr = window.sessionStorage.getItem('token')
  // 如果没有token
  if (!tokenStr) return next('/')
  // 如果有token
  next()
})

Vue.use(ElementUI);

Vue.config.productionTip = false
new Vue({
  render: h => h(App),
  //axios全局引入
  axios,
   //让vue知道我们的路由规则
  router, //可以简写router

}).$mount('#app')
